package iedcyt.acute.dataAccess.factories;

import iedcyt.acute.dataAccess.dao.maauco.Au0Dao;
import iedcyt.acute.dataAccess.dao.maauco.AupioDao;
import iedcyt.acute.dataAccess.dao.maauco.Co0Dao;
import iedcyt.acute.dataAccess.dao.maauco.Ma0Dao;
import iedcyt.acute.dataAccess.dao.maauco.RPDao;
import iedcyt.acute.dataAccess.idao.IDao;
import iedcyt.acute.dataAccess.idao.maauco.IAu0Dao;
import iedcyt.acute.dataAccess.idao.maauco.IAupioDao;
import iedcyt.acute.dataAccess.idao.maauco.ICo0Dao;
import iedcyt.acute.dataAccess.idao.maauco.IMa0Dao;
import iedcyt.acute.dataAccess.idao.maauco.IRPDao;
import iedcyt.acute.dataAccess.utils.BeansXML;
import iedcyt.acute.dataAccess.utils.Parameters;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class AbsSupFactoryDao extends AbsFactoryDao {

	private static AbsSupFactoryDao _instance;

	private IRPDao _RPDao;
	private IAupioDao _AupioDao;

	private IAu0Dao _Au0DaoSup;
	private ICo0Dao _Co0DaoSup;
	private IMa0Dao _Ma0DaoSup;

	private AbsSupFactoryDao() {
		super();
		startDaos();
	}

	/**
	 * Obtiene la instancia unica de la factoria
	 * @return
	 */
	public static AbsSupFactoryDao getInstance()
	{
		if (_instance == null) 
			_instance = new AbsSupFactoryDao();
		
		return _instance;
	}
	
	public IRPDao get_RPDao() {
		return _RPDao;
	}
	
	public IAupioDao get_AupioDao() {
		return _AupioDao;
	}
	
	public IAu0Dao get_Au0DaoSup() {
		return _Au0DaoSup;
	}

	public ICo0Dao get_Co0DaoSup() {
		return _Co0DaoSup;
	}
	
	public IMa0Dao get_Ma0DaoSup() {
		return _Ma0DaoSup;
	}


	@Override
	protected IDao getIDao() {
		return _Ma0DaoSup;
	}


	/**
	 * @see iedcyt.acute.dataAccess.factories.AbsFactoryDao#startDaos()
	 */
	@Override
	public void startDaos() {
		AbstractApplicationContext _context = new FileSystemXmlApplicationContext(Parameters.get_instance().getBeanFile());
		_context.registerShutdownHook();
		
		_RPDao= (RPDao) _context.getBean("rpDaoAux");
		_AupioDao= (AupioDao) _context.getBean("aupioDao");
		_Au0DaoSup = (Au0Dao) _context.getBean("au0DaoSup");
		_Au0DaoSup.create();
		_Co0DaoSup = (Co0Dao) _context.getBean("co0DaoSup");
		_Co0DaoSup.create();
		_Ma0DaoSup = (Ma0Dao) _context.getBean("ma0DaoSup");
		_Ma0DaoSup.create();
		
	}

	/**
	 * @see iedcyt.acute.dataAccess.factories.AbsFactoryDao#getPath()
	 */
	@Override
	public String getPath() {
		return BeansXML.getInstance().getDatabasePath("auxDataSource");
		
	}

	
}
